<?php

use Illuminate\Database\Seeder;

class AdminTablesSeeder extends Seeder
{

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // create a user.
        \App\Models\Administrator::create([
            'username' => 'admin',
            'password' => bcrypt('admin'),
            'name'     => '高级管理',
            'type'     => 'admin',
        ]);

        // create a role.
        \Encore\Admin\Auth\Database\Role::truncate();
        \Encore\Admin\Auth\Database\Role::create([
            'name' => '最高管理',
            'slug' => 'administrator',
        ]);
        \Encore\Admin\Auth\Database\Role::create([
            'name' => '运营',
            'slug' => 'operator',
        ]);

        // add role to user.
        \App\Models\Administrator::first()->roles()->save(\Encore\Admin\Auth\Database\Role::first());

        //create a permission
        \Encore\Admin\Auth\Database\Permission::truncate();
        \Encore\Admin\Auth\Database\Permission::insert([
            [
                'name'        => '最高权限',
                'slug'        => '*',
                'http_method' => '',
                'http_path'   => '*',
            ],
            [
                'name'        => '基础权限',
                'slug'        => 'dashboard',
                'http_method' => '',
                'http_path'   => "/auth/login\r\n/auth/logout\r\n/\r\n/auth/setting",
            ],
            [
                'name'        => '管理',
                'slug'        => 'auth.management',
                'http_method' => '',
                'http_path'   => "/auth/users\r\n/auth/roles\r\n/auth/permissions\r\n/auth/menu\r\n/auth/logs",
            ],
        ]);

        \Encore\Admin\Auth\Database\Role::first()->permissions()->save(\Encore\Admin\Auth\Database\Permission::first());

        // add default menus.
        \Encore\Admin\Auth\Database\Menu::truncate();
        \Encore\Admin\Auth\Database\Menu::insert([
            [
                'parent_id' => 0,
                'order'     => 1,
                'title'     => '首页',
                'icon'      => 'fa-bar-chart',
                'uri'       => '/',
            ],
            [
                'parent_id' => 0,
                'order'     => 2,
                'title'     => '管理',
                'icon'      => 'fa-tasks',
                'uri'       => '',
            ],
            [
                'parent_id' => 2,
                'order'     => 3,
                'title'     => '用户',
                'icon'      => 'fa-users',
                'uri'       => 'auth/users',
            ],
            [
                'parent_id' => 2,
                'order'     => 4,
                'title'     => '角色',
                'icon'      => 'fa-user',
                'uri'       => 'auth/roles',
            ],
            [
                'parent_id' => 2,
                'order'     => 5,
                'title'     => '权限',
                'icon'      => 'fa-ban',
                'uri'       => 'auth/permissions',
            ],
            [
                'parent_id' => 2,
                'order'     => 6,
                'title'     => '菜单',
                'icon'      => 'fa-bars',
                'uri'       => 'auth/menu',
            ],
            [
                'parent_id' => 2,
                'order'     => 7,
                'title'     => '操作日志',
                'icon'      => 'fa-history',
                'uri'       => 'auth/logs',
            ],
            [
                'parent_id' => 0,
                'order'     => 8,
                'title'     => '机器管理',
                'icon'      => 'fa-android',
                'uri'       => '',
            ],
            [
                'parent_id' => 8,
                'order'     => 9,
                'title'     => '机器',
                'icon'      => 'fa-magnet',
                'uri'       => '/machines',
            ],
            [
                'parent_id' => 8,
                'order'     => 10,
                'title'     => '运营',
                'icon'      => 'fa-male',
                'uri'       => '/operators',
            ],
            [
                'parent_id' => 0,
                'order'     => 11,
                'title'     => '商品管理',
                'icon'      => 'fa-cubes',
                'uri'       => '',
            ],
            [
                'parent_id' => 11,
                'order'     => 12,
                'title'     => '商品',
                'icon'      => 'fa-archive',
                'uri'       => '/products',
            ],
            [
                'parent_id' => 11,
                'order'     => 13,
                'title'     => '商品SKU',
                'icon'      => 'fa-bitbucket-square',
                'uri'       => '/product_skus',
            ],
            [
                'parent_id' => 0,
                'order'     => 14,
                'title'     => '团体管理',
                'icon'      => 'fa-bank',
                'uri'       => '',
            ],
            [
                'parent_id' => 14,
                'order'     => 15,
                'title'     => '管理员',
                'icon'      => 'fa-user-secret',
                'uri'       => '/team_leaders',
            ],
            [
                'parent_id' => 14,
                'order'     => 16,
                'title'     => '团体',
                'icon'      => 'fa-user-secret',
                'uri'       => '/teams',
            ],
            [
                'parent_id' => 14,
                'order'     => 17,
                'title'     => '申请',
                'icon'      => 'fa-user-plus',
                'uri'       => '/applies',
            ],
            [
                'parent_id' => 14,
                'order'     => 18,
                'title'     => '用户',
                'icon'      => 'fa-users',
                'uri'       => '/users',
            ],
            [
                'parent_id' => 14,
                'order'     => 19,
                'title'     => '分配日志',
                'icon'      => 'fa-balance-scale',
                'uri'       => '/dispatch_free_logs',
            ],
        ]);

        // add role to menu.
        \Encore\Admin\Auth\Database\Menu::find(2)->roles()->save(\Encore\Admin\Auth\Database\Role::first());
    }
}
